﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FineUI;

namespace lcmyjobs.Web.users
{
    public partial class reg_job : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                txtarea.Attributes.Add("readonly", "true");
                txttrade.Attributes.Add("readonly", "true");
                txtjob.Attributes.Add("readonly", "true");
                this.Title = string.Format("个人会员注册：求职意向   {0}", Application["webname"].ToString());
                if (Session["user_id_reg"] != null)
                {
                    int id = int.Parse(Session["user_id_reg"].ToString());
                    //this.lblName.Text = Session["user_name"].ToString();
                    getyears(id);
                    show(id);
                }
                else
                {
                    Response.Redirect("userlogin.html");
                }
            }

        }
        protected void gethf(int id)
        {
            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
            DataSet ds = bub.GetUserJob(id);
            if (ds.Tables[1].Rows.Count != 0)
            {
                hfareaid.Value = "";
                hfarea.Value = "";
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {
                    hfareaid.Value += ds.Tables[1].Rows[i][0].ToString() + ",";
                    hfarea.Value += ds.Tables[1].Rows[i][1].ToString() + ",";
                }
                hfareaid.Value = hfareaid.Value.Substring(0, hfareaid.Value.Length - 1);
                hfarea.Value = hfarea.Value.Substring(0, hfarea.Value.Length - 1);
            }
            if (ds.Tables[2].Rows.Count != 0)
            {
                hftradeid.Value = "";
                hftrade.Value = "";
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    hftradeid.Value += ds.Tables[2].Rows[i][0].ToString() + ",";
                    hftrade.Value += ds.Tables[2].Rows[i][1].ToString() + ",";
                }
                hftradeid.Value = hftradeid.Value.Substring(0, hftradeid.Value.Length - 1);
                hftrade.Value = hftrade.Value.Substring(0, hftrade.Value.Length - 1);
            }
            if (ds.Tables[3].Rows.Count != 0)
            {
                hfjobid.Value = "";
                hfjob.Value = "";
                for (int i = 0; i < ds.Tables[3].Rows.Count; i++)
                {
                    hfjobid.Value += ds.Tables[3].Rows[i][0].ToString() + ",";
                    hfjob.Value += ds.Tables[3].Rows[i][1].ToString() + ",";
                }
                hfjobid.Value = hfjobid.Value.Substring(0, hfjobid.Value.Length - 1);
                hfjob.Value = hfjob.Value.Substring(0, hfjob.Value.Length - 1);
            }

        }
        protected void show(int id)
        {
            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
            DataSet ds = bub.GetUserJob(id);
            if (ds.Tables[0].Rows.Count != 0)
            {
                string js = ds.Tables[0].Rows[0][0].ToString();
                if (js == "1") rbt1.Checked = true;
                else if (js == "2") rbt2.Checked = true;
                else if (js == "3") rbt3.Checked = true;
                else if (js == "4") rbt4.Checked = true;
                else if (js == "5") rbt5.Checked = true;
                string jt = ds.Tables[0].Rows[0][1].ToString();
                if (jt == "随时") rbtt1.Checked = true;
                else if (jt == "面谈") rbtt2.Checked = true;
                else if (jt.EndsWith("班")) { rbtt3.Checked = true; txttime.Text = jt.Substring(0, jt.IndexOf('以')); }
                txtpay.Text = ds.Tables[0].Rows[0][2].ToString();
                txtvision.Text = ds.Tables[0].Rows[0][3].ToString();
                txtyearpay.Text = ds.Tables[0].Rows[0][4].ToString();
                txtreward.Text = ds.Tables[0].Rows[0][5].ToString();
                txtjob_other.Text = ds.Tables[0].Rows[0]["jobpostother"].ToString();
            }
            if (ds.Tables[1].Rows.Count != 0)
            {
                hfareaid.Value = "";
                hfarea.Value = "";
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {
                    hfareaid.Value += ds.Tables[1].Rows[i][0].ToString() + ",";
                    hfarea.Value += ds.Tables[1].Rows[i][1].ToString() + ",";
                }
                hfareaid.Value = hfareaid.Value.Substring(0, hfareaid.Value.Length - 1);
                hfarea.Value = hfarea.Value.Substring(0, hfarea.Value.Length - 1);
                txtarea.Text = hfarea.Value;
            }
            if (ds.Tables[2].Rows.Count != 0)
            {
                hftradeid.Value = "";
                hftrade.Value = "";
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    hftradeid.Value += ds.Tables[2].Rows[i][0].ToString() + ",";
                    hftrade.Value += ds.Tables[2].Rows[i][1].ToString() + ",";
                }
                hftradeid.Value = hftradeid.Value.Substring(0, hftradeid.Value.Length - 1);
                hftrade.Value = hftrade.Value.Substring(0, hftrade.Value.Length - 1);
                txttrade.Text = hftrade.Value;
            }
            if (ds.Tables[3].Rows.Count != 0)
            {
                hfjobid.Value = "";
                hfjob.Value = "";
                for (int i = 0; i < ds.Tables[3].Rows.Count; i++)
                {
                    hfjobid.Value += ds.Tables[3].Rows[i][0].ToString() + ",";
                    hfjob.Value += ds.Tables[3].Rows[i][1].ToString() + ",";
                }
                hfjobid.Value = hfjobid.Value.Substring(0, hfjobid.Value.Length - 1);
                hfjob.Value = hfjob.Value.Substring(0, hfjob.Value.Length - 1);
                txtjob.Text = hfjob.Value;
            }
        }
        protected void getyears(int id)
        {
            SqlParameter[] parameters = {			 
			 			 new SqlParameter("@uid", SqlDbType.Int,4)};
            parameters[0].Value = id;
            lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
            int i = 0;
            i = bub.getyears(parameters);
            this.hfyears.Value = i.ToString();
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (Session["user_id_reg"] != null)
                {
                    int uid = int.Parse(Session["user_id_reg"].ToString());
                    int  rid1 = 0, rid2 = 0, rid3 = 0, jid1 = 0, jid2 = 0, jid3 = 0, tid1 = 0, tid2 = 0, tid3 = 0, jsid = 0;
                    float yearpay = 0, reward = 0, pay = 0;
                    DateTime dt = DateTime.Now;
                    string area_name1 = "", area_name2 = "", area_name3 = "", job_name1 = "", job_name2 = "", job_name3 = "", tradename1 = "", tradename2 = "", tradename3 = "", jobtime = "", vision = "", jobnameother = "";
                    if (rbt1.Checked) jsid = 1;
                    else if (rbt2.Checked) jsid = 2;
                    else if (rbt3.Checked) jsid = 3;
                    else if (rbt4.Checked) jsid = 4;
                    else if (rbt5.Checked) jsid = 5;
                    if (rbtt1.Checked) jobtime = "随时";
                    else if (rbtt2.Checked) jobtime = "面谈";
                    else if (rbtt3.Checked)
                    {
                        if (txttime.Text.Trim() != "")
                            dt = DateTime.Parse(txttime.Text.Trim());
                        jobtime = txttime.Text + "以后随时上班";

                    }
                    if (txtyearpay.Text != "")
                        yearpay = float.Parse(txtyearpay.Text);
                    if (txtreward.Text != "")
                        reward = float.Parse(txtreward.Text);
                    if (txtpay.Text != "")
                    {
                        pay = float.Parse(txtpay.Text);
                    }
                    vision = txtvision.Text;
                    string[] a = txtarea.Text.Split(',');
                    if (txtarea.Text != "")
                    {
                        if (a.Length > 0)
                        { area_name1 = a[0]; }
                        if (a.Length > 1)
                        { area_name2 = a[1]; }
                        if (a.Length > 2)
                        { area_name3 = a[2]; }
                    }
                    if (hfareaid.Value != "")
                    {
                        a = hfareaid.Value.Split(',');
                        if (a.Length > 0)
                        { rid1 = int.Parse(a[0]); }
                        if (a.Length > 1)
                        { rid2 = int.Parse(a[1]); }
                        if (a.Length > 2)
                        { rid3 = int.Parse(a[2]); }
                    }
                    if (txtjob.Text != "")
                    {
                        a = txtjob.Text.Split(',');
                        if (a.Length > 0)
                        { job_name1 = a[0]; }
                        if (a.Length > 1)
                        { job_name2 = a[1]; }
                        if (a.Length > 2)
                        { job_name3 = a[2]; }
                    }
                    else if (txtjob_other.Text != "" || txtjob_other.Text != "若无合适选项在此处填写")
                    {
                        jobnameother = txtjob_other.Text;
                    }

                    if (hfjobid.Value != "")
                    {
                        a = hfjobid.Value.Split(',');
                        if (a.Length > 0)
                        { jid1 = int.Parse(a[0]); }
                        if (a.Length > 1)
                        { jid2 = int.Parse(a[1]); }
                        if (a.Length > 2)
                        { jid3 = int.Parse(a[2]); }
                    }
                    if (txttrade.Text != "")
                    {
                        a = txttrade.Text.Split(',');
                        if (a.Length > 0)
                        { tradename1 = a[0]; }
                        if (a.Length > 1)
                        { tradename2 = a[1]; }
                        if (a.Length > 2)
                        { tradename3 = a[2]; }
                    }
                    if (hftradeid.Value != "")
                    {
                        a = hftradeid.Value.Split(',');
                        if (a.Length > 0)
                        { tid1 = int.Parse(a[0]); }
                        if (a.Length > 1)
                        { tid2 = int.Parse(a[1]); }
                        if (a.Length > 2)
                        { tid3 = int.Parse(a[2]); }
                    }
                    SqlParameter[] parameters = {			 
			 			 new SqlParameter("@uid", SqlDbType.Int,4),                 // 0
			 			 new SqlParameter("@area_name2", SqlDbType.NVarChar,20),    // 1
			 			 new SqlParameter("@area_name3", SqlDbType.NVarChar,20),    // 2
			 			 new SqlParameter("@jid1", SqlDbType.Int,4),                // 3
			 			 new SqlParameter("@jid2", SqlDbType.Int,4),                // 4
			 			 new SqlParameter("@jid3", SqlDbType.Int,4),                // 5
			 			 new SqlParameter("@job_name1", SqlDbType.NVarChar,20),     // 6
			 			 new SqlParameter("@job_name2", SqlDbType.NVarChar,20),     // 7
			 			 new SqlParameter("@job_name3", SqlDbType.NVarChar,20),     // 8
			 			 new SqlParameter("@tid1", SqlDbType.Int,4),                // 9
			 			 new SqlParameter("@tid2", SqlDbType.Int,4),                // 10
			 			 new SqlParameter("@jsid", SqlDbType.Int,4),                // 11
			 			 new SqlParameter("@tid3", SqlDbType.Int,4),                // 12
			 			 new SqlParameter("@tradename1", SqlDbType.NVarChar,20),    // 13
			 			 new SqlParameter("@tradename2", SqlDbType.NVarChar,20),    // 14
			 			 new SqlParameter("@tradename3", SqlDbType.NVarChar,20),    // 15
			 			 new SqlParameter("@yearpay", SqlDbType.Int,4),             // 16
			 			 new SqlParameter("@reward", SqlDbType.Float,8),            // 17
			 			 new SqlParameter("@jobtime", SqlDbType.NVarChar,20),       // 18
			 			 new SqlParameter("@pay", SqlDbType.Float,8),               // 19
			 			 new SqlParameter("@vision", SqlDbType.NVarChar,500),       // 20
			 			 new SqlParameter("@rid1", SqlDbType.Int,4),                // 21
			 			 new SqlParameter("@rid2", SqlDbType.Int,4),                // 22
			 			 new SqlParameter("@rid3", SqlDbType.Int,4),                // 23
			 			 new SqlParameter("@area_name1", SqlDbType.NVarChar,20),    // 24
                         new SqlParameter("@jobtimes", SqlDbType.DateTime),         // 25
                         new SqlParameter("@status", SqlDbType.Int,4),              // 26
                         new SqlParameter("@jobnameother", SqlDbType.NVarChar,20)   // 27
			 			 };
                    parameters[0].Value = uid;
                    if (area_name2 != "")
                        parameters[1].Value = area_name2;
                    if (area_name3 != "")
                        parameters[2].Value = area_name3;
                    if (jid1 != 0)
                        parameters[3].Value = jid1;
                    if (jid2 != 0)
                        parameters[4].Value = jid2;
                    if (jid3 != 0)
                        parameters[5].Value = jid3;
                    if (job_name1 != "")
                        parameters[6].Value = job_name1;
                    if (job_name2 != "")
                        parameters[7].Value = job_name2;
                    if (job_name3 != "")
                        parameters[8].Value = job_name3;
                    if (tid1 != 0)
                        parameters[9].Value = tid1;
                    if (tid2 != 0)
                        parameters[10].Value = tid2;
                    parameters[11].Value = jsid;
                    if (tid3 != 0)
                        parameters[12].Value = tid3;
                    if (tradename1 != "")
                        parameters[13].Value = tradename1;
                    if (tradename2 != "")
                        parameters[14].Value = tradename2;
                    if (tradename3 != "")
                        parameters[15].Value = tradename3;
                    if (yearpay > 0)
                        parameters[16].Value = yearpay;
                    if (reward > 0)
                        parameters[17].Value = reward;
                    parameters[18].Value = jobtime;
                    parameters[19].Value = pay;
                    parameters[20].Value = vision;
                    if (rid1 != 0)
                        parameters[21].Value = rid1;
                    if (rid2 != 0)
                        parameters[22].Value = rid2;
                    if (rid3 != 0)
                        parameters[23].Value = rid3;
                    if (area_name1 != "")
                        parameters[24].Value = area_name1;
                    parameters[25].Value = dt;
                    parameters[26].Value = 0;
                    parameters[27].Value = jobnameother;
                    BLL.user_basic bub = new BLL.user_basic();
                    try
                    {
                        bub.addjob(parameters);
                        //更新hf如跳转就不用更新
                        //gethf(uid);
                        Session["user_id"] = Session["user_id_reg"];
                        Session["user_id_reg"] = null;
                        if(Session["user_name_reg"] != null && Session["user_name"] ==null){
                            Session["user_name"] = Session["user_name_reg"];
                            Session["user_name_reg"] = null;
                        }
                        if (Session["user_id"] != null && Session["user_name"] != null)
                        {
                            Response.Redirect("user_main.html");
                        }
                        else
                        {
                            Response.Redirect("user_login.html");
                        }
                    }
                    catch (Exception ex)
                    {

                        Maticsoft.Common.MessageBox.Show(this, "保存失败！" + ex.Message.ToString());
                    }
                }

            }
        }

        protected void btn_why_Click(object sender, EventArgs e)
        {

            //Alert alert = new Alert();
            string msg = "<div style='width:250px;text-indent:2em;line-height:20px;'><p style='padding-Bottom:5px; >  悬赏求职：更准确、更快捷。</p>";
            msg += "<p style='padding-Bottom:5px; >  更准确----提供专业的人才选择工具，帮助您深度甄选工作。 基于人才胜任素质的评测工具辅助单位招聘。颠覆被动“等待”招聘的传统方式。</p>";
            msg += "<p style='padding-Bottom:5px; >  更快捷----发挥社会力量，动员群众，借助猎手人脉资源关系，让您的悬赏信息迅速覆盖目标群体，快捷找到合适工作。</p></div>";

            /*
            alert.Message = msg;
            alert.Icon = Icon.Help;
            alert.Title = "为什么要悬赏求职";
            alert.Show();
             */
            Alert.Show(msg);
        }
    }
}